# Example plugin script
# needs to define init() ... otherwise it's dumped after load
irc = None

def init(bot):
    global irc
    bot.cmd.events['PRIVMSG'].subscribe(privmsg)
    bot.cmd.events['NOTICE'].subscribe(notice)
    bot.cmd.events['JOIN'].subscribe(join)
    irc = bot

def join(sender, args):
    global irc
    ops = ["kif.angrycoder.org", "c-76-25-4-66.hsd1.co.comcast.net"]
    if sender.host in ops:
        irc.mode(args[0], "+o", sender.nick)
    pass
    
def notice(sender, args):
    global irc
    if args[0] == "get lost":
        irc.quit("quit command recieved from %s" % sender.nick)
        pass
def privmsg(sender, args):
    global irc
    msg = args[0].split()

    if msg:
        if msg[0] == "!suck":
            irc.privmsg(args[2], "Man... sloat sucks.")
        if msg[0] == "!assrape":
            if irc.chmgr.get(args[2]).isop(sender.nick):
                try: name = msg[1]
                except: name = ""
                if irc.nickname == name:
                    irc.kick(args[2], sender.nick, "Assraped %s by request" %(sender.nick))            
                else:
                    irc.kick(args[2], name, "Assraped")
        if msg[0] == "\001VERSION\001":
            irc.ctcp_reply(sender.nick, "VERSION %s" % irc.version)
        if msg[0] == "debug":
            print irc.chmgr.channels
        if msg[0] == "ops":
            chan = irc.chmgr.get(args[2])
            irc.privmsg(args[2], "Ops: %s" % " ".join(chan.users_op))
        if msg[0] == "voices":
            chan = irc.chmgr.get(args[2])
            irc.privmsg(args[2], "Voices: %s" % " ".join(chan.users_voice))
        if msg[0] == "test":
            for a in range(5):
                irc.privmsg(args[2], "Test %d" % a)
        if msg[0] == "test2":
            irc.privmsg("#liek,#test2", "Testing.")
        if sender.nick == 'kaboofa':
            if msg[0] == "load":
                irc.load_plugin(msg[1])
            elif msg[0] == "unload":
                irc.unload_plugin(msg[1])
        
    if args[0] == "get lost":
        if irc.chmgr.get(args[2]).isop(sender.nick):
            irc.terminate("you're the boss")
            pass
